package top.lixunda.ecommerce.server.good.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import top.lixunda.commerce.common.core.entity.MessageObject;
import top.lixunda.ecommerce.server.business.BaseController;
import top.lixunda.ecommerce.server.good.api.controller.IOrderReviewController;
import top.lixunda.ecommerce.server.good.api.entity.dto.OrderReviewInsertDTO;
import top.lixunda.ecommerce.server.good.api.entity.vo.OrderReviewConvertVO;
import top.lixunda.ecommerce.server.good.service.IOrderReviewDetailService;

import java.util.List;

/**
 * 订单评论管理
 *
 * @author lixunda
 * @version time:2020/3/7 11:06
 */
@Slf4j
@RestController
public class OrderReviewController extends BaseController
        implements IOrderReviewController {

    private final IOrderReviewDetailService orderReviewDetailService;

    @Autowired
    public OrderReviewController(IOrderReviewDetailService orderReviewDetailService) {
        this.orderReviewDetailService = orderReviewDetailService;
    }

    /**
     * 普通用户调用，订单评论
     *
     * @param orderReviewInsertDTO 评论数据
     * @return 是否评论成功
     */
    @Override
    public MessageObject<OrderReviewConvertVO> reviewOrderByOrderId(OrderReviewInsertDTO orderReviewInsertDTO) {
        OrderReviewConvertVO orderReviewConvertVO = orderReviewDetailService.reviewOrderByOrderId(orderReviewInsertDTO);
        return getSuccessMessageObject("评论成功", orderReviewConvertVO);
    }

    /**
     * 普通用户调用，订单评论，批量
     *
     * @param orderReviewInsertList 评论数据
     * @return 是否评论成功
     */
    @Override
    public MessageObject<List<OrderReviewConvertVO>> reviewOrdersByOrderIds(List<OrderReviewInsertDTO> orderReviewInsertList) {
        List<OrderReviewConvertVO> list = orderReviewDetailService.reviewOrdersByOrderIds(orderReviewInsertList);
        return getSuccessMessageObject("评论成功", list);
    }

}
